package com.kaihong.template.ble;

import java.util.UUID;

/**
 * Ble Profile uid
 */
public enum BleProfileUuid {
    /**
     * Blood pressure service ble profile uuid.
     */
    BLOOD_PRESSURE_SERVICE("00001810-0000-1000-8000-00805f9b34fb"),

    /**
     * Blood pressure characteristic ble profile uuid.
     */
    BLOOD_PRESSURE_CHARACTERISTIC("00002a35-0000-1000-8000-00805f9b34fb"),

    /**
     * Client characteristic config descriptor ble profile uuid.
     */
    CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR("00002902-0000-1000-8000-00805f9b34fb"),

    /**
     * Blood intermediate cuff pressure characteristic ble profile uuid.
     */
    BLOOD_INTERMEDIATE_CUFF_PRESSURE_CHARACTERISTIC("00002a36-0000-1000-8000-00805f9b34fb"),

    /**
     * Glucose service ble profile uuid.
     */
    GLUCOSE_SERVICE("00001808-0000-1000-8000-00805f9b34fb"),

    /**
     * Glucose measurement characteristic ble profile uuid.
     */
    GLUCOSE_MEASUREMENT_CHARACTERISTIC("00002A18-0000-1000-8000-00805f9b34fb"),

    /**
     * Glucose record access control point characteristic ble profile uuid.
     */
    GLUCOSE_RECORD_ACCESS_CONTROL_POINT_CHARACTERISTIC("00002A52-0000-1000-8000-00805f9b34fb"),

    /**
     * Characteristic current time ble profile uuid.
     */
    CHARACTERISTIC_CURRENT_TIME("00002a2b-0000-1000-8000-00805f9b34fb"),

    /**
     * Unknown uuid ble profile uuid.
     */
    UNKNOWN_UUID("");

    private final String uuidValue;

    BleProfileUuid(String value) {
        this.uuidValue = value;
    }

    /**
     * get BleProfileUuid instance by uuid
     *
     * @param uuid Unique identifier
     * @return instance
     */
    public static BleProfileUuid getEnum(UUID uuid) {
        BleProfileUuid[] profileUuids = values();
        if (profileUuids == null) {
            return UNKNOWN_UUID;
        }
        for (BleProfileUuid profileUuid : profileUuids) {
            if (profileUuid.isSame(uuid)) {
                return profileUuid;
            }
        }
        return UNKNOWN_UUID;
    }

    /**
     * Whether the content is consistent
     *
     * @param uuid Unique identifier
     * @return true is the same, otherwise false
     */
    public boolean isSame(UUID uuid) {
        if (uuid != null) {
            return getUuid().toString().equalsIgnoreCase(uuid.toString());
        }
        return false;
    }

    /**
     * Generate UUID instance by uuidValue
     *
     * @return UUID
     */
    public UUID getUuid() {
        return UUID.fromString(this.uuidValue);
    }

    /**
     * Get uuid value
     *
     * @return Uuid value
     */
    public String getValue() {
        return this.uuidValue;
    }
}
